package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 965. 单值二叉树
 * 深度优先搜索
 * 2022-05-24 每日一题
 *
 * @author fy
 * @date 2022/5/24 8:08
 */
public class Solution965 {

    public boolean isUnivalTree(TreeNode root) {
        return isUnivalTree(root, root.val);
    }

    private boolean isUnivalTree(TreeNode node, int val) {
        if (node == null) {
            return true;
        }
        return node.val == val && isUnivalTree(node.left, val) && isUnivalTree(node.right, val);
    }

}
